/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#include "HydraxManager.h"

namespace PQEngine
{
	//ocean creature manger
	//manager fishes
	HydraxManager::HydraxManager()
	{
		hydrax=NULL;
		updateHydrax=false;
	}

	void HydraxManager::init(Ogre::RenderWindow *renderWindow, Ogre::SceneManager *sceneMgr,Ogre::Camera *camera)
	{
		_sceneMgr=sceneMgr;
		hydrax = new Hydrax::Hydrax(sceneMgr, camera, renderWindow->getViewport(0));
			// Create our projected grid module  
		Hydrax::Module::SimpleGrid *module=new Hydrax::Module::SimpleGrid(hydrax,new Hydrax::Noise::Perlin(/*Generic one*/),Hydrax::MaterialManager::NM_RTT);

		/*
			Hydrax::Module::ProjectedGrid *module 
				= new Hydrax::Module::ProjectedGrid(// Hydrax parent pointer
													hydrax,
													// Noise module
													new Hydrax::Noise::Perlin( ),
													// Base plane
													Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0)),
													// Normal mode
													Hydrax::MaterialManager::NM_RTT,
													// Projected grid options
													Hydrax::Module::ProjectedGrid::Options( ));
		*/
			hydrax->setModule(static_cast<Hydrax::Module::Module*>(module));
			hydrax->loadCfg("Hydrax.hdx");
			hydrax->create();
			
			hydrax->getMaterialManager()->addDepthTechnique(
				static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("Island"))->createTechnique());
			updateHydrax=true;

	}

	void HydraxManager::update(float deltaT)
	{
		if(hydrax){
			if(updateHydrax){
				hydrax->update(deltaT/1000.0f);
			}
		}
	}
}
